﻿using SXFramWork.Core;
using SXFramWork.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SXFramWork.API
{
    public class PermissionHandler : IPermissionHandler
    {
        private readonly ISysUserService _userService;
        private readonly ILoginInfo _loginInfo;
        public PermissionHandler(ISysUserService sysUserService,ILoginInfo loginInfo)
        {
            _userService = sysUserService;
            _loginInfo = loginInfo;
        }
        public async Task<bool> ValidateAsync(IDictionary<string, string> routeValues,string httpMethod)
        {
            //return await Task.FromResult(true);
            var permissions = await _userService.QueryPermissionList(_loginInfo.UserId);
            var area = routeValues["area"];
            var controller = routeValues["controller"];
            var action = routeValues["action"];
            return permissions.Any(m => m.EqualsIgnoreCase($"{area}_{controller}_{action}"));
        }
    }
}
